#include<iostream>
#include<cstdlib>
#include"BiTree.h"
using namespace std;

// count greater than x
int Count_GT_X(BTNode* root, ElemType x)
{
	if (!root->lchild && !root->rchild)
		return root->data >= x ? 1 : 0;
	else if (!root->lchild)
		return Count_GT_X(root->rchild, x);
	else if (!root->rchild)
		return Count_GT_X(root->lchild, x);

	return root->data >= x ? 1 + Count_GT_X(root->lchild, x) + Count_GT_X(root->rchild, x) : Count_GT_X(root->lchild, x) + Count_GT_X(root->rchild, x);
}

int main()
{
	/*
		1
	5       2
		 3     4
	*/
	BTNode* BTree;
	ElemType a[] = { 1,5,2,3,4 };
	ElemType b[] = { 5,1,3,2,4 };

	BTree = CreateBTree(a, b, 5);

	int count = Count_GT_X(BTree, 3);

	cout << count << endl;

	return 0;
}